import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Log {
	
	int id;
    String tableName;
    String descrtiption;
    String notes;
    
    public Log(int id, String tableName, String description, String notes){
    	this.id = id;
    	this.tableName = tableName;
    	this.descrtiption = description;
    	this.notes = notes;
    	
		try {
			FileWriter file = new FileWriter(this.tableName);
			BufferedWriter writer = new BufferedWriter(file);
			writer.write("\r\n\tTime\t\t\tDescription\r\n");
			writer.write("\t-----------\t\t-------------------\r\n");
			writer.close();
			this.writeInLog("Log created.");
		} catch (IOException e) {
			System.out.println("File doesn't exist!");
		}
    }

    public String getDescrtiption() {
        return descrtiption;
    }

    public String getNotes() {
        return notes;
    }

    public String getTableName() {
        return tableName;
    }
    
    public String now() {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm dd/MM");
        return sdf.format(cal.getTime());
    }
    
    // the method to write in the log
    public void writeInLog(String s){
    	try {
    		FileWriter file = new FileWriter(this.tableName, true);
			BufferedWriter writer = new BufferedWriter(file);
			writer.write("\t"+this.now()+"\t\t"+s+"\r\n");
			writer.close();
		} catch (IOException e) {
			System.out.println("Error with the log writer.");
		}
    }

}
